package com.zzyl.utils;

import com.zzyl.common.core.domain.model.LoginUser;

import com.zzyl.common.utils.ServletUtils;
import com.zzyl.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class CurrentUserUtil {

    @Autowired
    private TokenService tokenService;

    public Long getCurrentUserId() {
        HttpServletRequest request = ServletUtils.getRequest();
        LoginUser loginUser = tokenService.getLoginUser(request);
        if (loginUser != null && loginUser.getUser() != null) {
            return loginUser.getUserId();
        }
        return null;
    }
}
